<?php
/**
 * 
 */

class Application_Model_Posisi extends Zend_Db_Table_Abstract
{
    protected $_name = 'tabel_posisi';
    
    public function posisiBaru($posisi, $keterangan)
    {
        $data = array('nama_posisi' => $posisi, 'keterangan_posisi' => $keterangan);
        $this->insert($data);
    }
    
    public function getPosisi($id) {
        $id = (int)$id;
        $row = $this->fetchRow('id_posisi = '.$id);
        if(!$row)
            throw  new Exception('Data dengan id=$id tidak ditemukan');
        else
            return $row->toArray ();
    }
    
    public function posisiUpdate($id, $posisi, $keterangan)
    {
        $this->update(array('nama_posisi' => $posisi, 'keterangan_posisi' => $keterangan), 'id_posisi = '.(int)$id);   
    }
    
    public function posisiDelete($id){
        $this->delete('id_posisi = '.(int)$id);
    }


    public function checkPosisi($nama) {
        $select = $this->select();
        $select->where("nama_posisi= ?",$nama);
        $row = $this->fetchAll($select)->count();
        if($row > 0)
            return true;
        else
            return false;
    }
    
    public function  getAllData()
    {
        $data = $this->fetchAll()->toArray();
        return $data;
    }
    
    public function checkRowPosisi()
    {
        $row = $this->fetchAll()->count();
        return $row;
    }
}